<template>
  <Table
    ref="tableRef"
    :url="URL_QUERYEQUIPMENTMODEL"
    :columns="data.columns"
    :handles="data.handles"
    :toolbar="data.toolbar"
    :query="data.query"
  ></Table>
</template>
  
  <script lang="ts" setup name="modelManagementList">
import Table from '@/components/table/index.vue';
import {
  URL_QUERYEQUIPMENTMODEL,
  delEquipmentModel,
} from '@/service/apis/config';
import { queryDicByParent } from '@/service/apis/api';

const router = useRouter();

const tableRef = ref();

const emit = defineEmits(['get-update']);
onActivated(() => {
  emit('get-update', (flag: boolean) => {
    if (flag) {
      tableRef.value?.getData();
    }
  });
});

const data = reactive({
  columns: [
    {
      prop: 'equipmentBrandName',
      label: '电桩品牌',
    },
    {
      prop: 'equipmentModel',
      label: '电桩型号',
    },
    {
      prop: 'number',
      label: '充电枪数量',
    },
    {
      prop: 'type',
      label: '电桩类型',
      dic: [] as any,
      type: Number,
    },
    {
      prop: 'power',
      label: '电桩功率（kW）',
    },
    {
      prop: 'createTime',
      label: '创建时间',
    },
  ],
  handles: [
    {
      label: '修改',
      permission: 'modelManagementList.edit',
      handle: (row: any) => {
        console.log('编辑---', row);
        router.push({
          name: 'modelManagementEdit',
          query: row,
        });
      },
    },
    {
      label: '删除',
      color: '#FA3939',
      permission: 'modelManagementList.delete',
      handle: (row: any) => {
        ElMessageBox.confirm('此操作将永久删除该数据，是否继续？', '提示', {
          confirmButtonText: '确认',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          delEquipmentModel({
            id: row.id,
          }).then((res: any) => {
            tableRef.value.getData();
          });
        });
      },
    },
  ],
  toolbar: [
    {
      label: '新增',
      permission: 'modelManagementList.add',
      icon: 'icon-add',
      type: 'primary',
      handle: (row: any) => {
        router.push({
          name: 'modelManagementAdd',
        });
      },
    },
  ],
  query: [
    {
      label: '电桩品牌',
      prop: 'brandName',
      comName: 'input',
      props: {
        placeholder: '请输入电桩品牌',
      },
    },
    {
      label: '电桩类型',
      prop: 'type',
      comName: 'select',
      props: {
        placeholder: '请选择电桩类型',
        options: [] as any,
      },
    },
    {
      label: '电桩型号',
      prop: 'equipmentModel',
      comName: 'input',
      props: {
        placeholder: '请输入电桩型号',
      },
    },
    {
      label: '创建时间',
      prop: 'date',
      comName: 'date',
      keys: ['startTime', 'endTime'],
      props: {
        type: 'daterange',
      },
    },
  ],
});

queryDicByParent({ listDtos: ['equipmentModelType'] }).then((res: any) => {
  // optionsS.equipmentModelType = res.equipmentModelType;
  data.columns[3].dic = [...res.equipmentModelType];
  data.query[1].props.options = [...res.equipmentModelType];
});
</script>